package com.xjtu.chapter08.thread;

/**
 * @author yjq
 * @version 1.0
 * @date 2021/8/30 10:06
 */
public class InterruptTest1 extends Thread{
    private int x = 0;

    @Override
    public void run() {
        while(true){
            System.out.println("running");
            for (int i = 0; i <90000 ; i++) {
                x = (int)(Math.random()*100);
            }
        }
    }

    public static void main(String[] args) throws InterruptedException {
        Thread thread = new InterruptTest1();
        System.out.println("starting thread");
        thread.start();
        thread.sleep(300);
        System.out.println("try to interrupt thread...");
        thread.interrupt();
        Thread.sleep(3000);
    }
}
